//
//  Town.m
//  05-CollectionTraversalHomeWork
//
//  Created by 曹曹 on 16/7/11.
//  Copyright © 2016年 曹曹. All rights reserved.
//

#import "Town.h"

@implementation Town
- (void)dealloc {
    [_name release];
    [_number release];
    [super dealloc];
}
// 在实例方法中, self代表实例对象(调用者)
- (instancetype)initWithName:(NSString *)name {
    return [self initWithName:name number:nil];
}
// 在类方法中, self代表类本身
+ (instancetype)townWithName:(NSString *)name {
    return [[[self alloc] initWithName:name number:nil] autorelease];
}
/** 指派初始化方法 */
- (instancetype)initWithName:(NSString *)name number:(NSString *)number {
    self = [super init];
    if (self) {
        _name = [name copy];
        _number = [number copy];
    }
    return self;
}
+ (instancetype)townWithName:(NSString *)name number:(NSString *)number {
    return [[[self alloc] initWithName:name number:number] autorelease];
}
- (instancetype)initWithTempCity:(TempCity *)tempCity {
    return [self initWithName:tempCity.cityName number:tempCity.cityNumber];
}
+ (instancetype)townWithTempCity:(TempCity *)tempCity {
    return [[[self alloc] initWithTempCity:tempCity] autorelease];
}
- (NSString *)description {
    return [NSString stringWithFormat:@"%@, %@", _name, _number];
}
@end
